/ leetcodesolve / Palindrome Number.py
swadhinbiswas test commit · 3/25/2024
74b485a
24 lines · 512 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution:
    def isPalindrome(self, x: int) -> bool:
        if x < 0:
            return False
        while x > 0:
            if x % 10 != x // 10 ** (len(str(x)) - 1):
                return False
            x = (x % 10 ** (len(str(x)) - 1)) // 10
        return True



if __name__ == "__main__":
  #testcase1
  s = Solution()
  a=s.isPalindrome(121)
  b=s.isPalindrome(-121)
  c=s.isPalindrome(10)
  d=s.isPalindrome(1000021)
  print(a) #True
  print(b) #False
  print(c) #False
  print(d) #False